home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / wasm.arc / KEY.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-02-19  |  6.0 KB  |  160 lines

  1.            TITLE     'Wolfware Sample Program','Key Reassignment'
  2.  
  3. ;-------------------------------------------------------;
  4. ;               DOS 2.0 Key Reassignment                ;
  5. ;                                                       ;
  6. ; Reassign any string to any key via DOS 2.0.  The      ;
  7. ; ANSI.SYS device driver must be included into the      ;
  8. ; operating system (see your DOS manual).  Once         ;
  9. ; assembled, to reassign a key, type:                   ;
  10. ;                                                       ;
  11. ; KEY <key code> <string>                               ;
  12. ;                                                       ;
  13. ; The parameters must be separated by a single space.   ;
  14. ; Each parameter may consist of any combination of      ;
  15. ; strings in double quotes and decimal ASCII codes,     ;
  16. ; seperated by semicolons.                              ;
  17. ;                                                       ;
  18. ; The key to reset (first parameter) should be the      ;
  19. ; key's character code (one or two bytes).  The new     ;
  20. ; assignment (second parameter) can be any combination  ;
  21. ; of strings and ASCII values.                          ;
  22. ;                                                       ;
  23. ; Examples:                                             ;
  24. ;                                                       ;
  25. ; KEY "g" "h"                                           ;
  26. ;   Assign lower-case h to the lower-case g key.        ;
  27. ;                                                       ;
  28. ; KEY 0;59 19                                           ;
  29. ;   Assigns ^S to the F1 key.  0;59 is the key code for ;
  30. ;   F1.  Makes F1 act like Ctl NumLock when you are,    ;
  31. ;   for instance, TYPEing out a file.                   ;
  32. ;                                                       ;
  33. ; KEY 0;68 "DIR";13                                     ;
  34. ;   Assign DIR plus a carriage return to the F10 key.   ;
  35. ;                                                       ;
  36. ; The extended codes for all applicable keys can be     ;
  37. ; found in the BASIC manual right after the ASCII       ;
  38. ; character table.  Most application programs by-pass   ;
  39. ; the DOS keyboard routines (i.e. the reassignments     ;
  40. ; won't work for them).  Keyboard reaasignment by this  ;
  41. ; method is probably best used for setting up the       ;
  42. ; function keys to use from the DOS command level.      ;
  43. ;-------------------------------------------------------;
  44.  
  45.            PROC      FAR
  46. INPUT      EQU       [80H]          ;parameter location
  47.  
  48. ;----- print message
  49.  
  50.            MOV       DX,OFFSET KEYMESS ;message location
  51.            CALL      STR_DISPLAY    ;string display
  52.  
  53. ;----- number of characters
  54.  
  55.            MOV       CL,BYTE INPUT  ;number of characters
  56.            SUB       CH,CH
  57.            CMP       CL,1           ;check if too few
  58.            JB        KEYERROR       ;jump if so
  59.  
  60. ;----- print input and end CR
  61.  
  62.            PUSH      CX
  63.            MOV       SI,OFFSET INPUT + 2 ;start after space
  64.            PUSH      SI
  65.  
  66.            MOV       DX,OFFSET KEYMESS2 ;message location
  67.            CALL      STR_DISPLAY    ;string display
  68.  
  69. KEYILOOP   LODSB                    ;load next byte
  70.            CALL      DISPLAY        ;display
  71.            LOOP      KEYILOOP       ;loop CX times
  72.  
  73. ;----- move a line down
  74.  
  75.            MOV       AL,10          ;byte to display, LF
  76.            CALL      DISPLAY        ;display
  77.  
  78.            POP       DI
  79.            POP       BX
  80.  
  81. ;----- scan for space
  82.  
  83.            DEC       BX             ;do not count initial space
  84.            MOV       CX,BX          ;number of characters to search
  85.            MOV       AL,' '         ;look for space
  86.  
  87.            REPNE
  88.            SCASB                    ;scan until found or no more
  89.  
  90. ;----- add semicolon
  91.  
  92.            JNE       KEYERROR       ;jump if not found
  93.            MOV       BYTE [DI-1],59 ;save semicolon to location
  94.  
  95. ;----- add start code
  96.  
  97.            MOV       AX,CTL_START   ;load starting control
  98.            MOV       WORD INPUT,AX  ;save
  99.  
  100. ;----- add end code
  101.  
  102.            MOV       AX,CTL_END     ;load end control
  103.            MOV       [INPUT+BX+2],AX ;save
  104.  
  105. ;----- reset key
  106.  
  107.            MOV       DX,OFFSET INPUT ;control string location
  108.            CALL      STR_DISPLAY    ;string display
  109.            INT       20H            ;exit
  110.  
  111. ;----- error in parameters
  112.  
  113. KEYERROR   MOV       DX,OFFSET KEYEMESS ;error message location
  114.            CALL      STR_DISPLAY    ;string display
  115.            INT       20H            ;exit
  116.  
  117. ;-----------------------;
  118. ;        DISPLAY        ;
  119. ; Display the character ;
  120. ; in AL to the screen.  ;
  121. ;-----------------------;
  122.  
  123. DISPLAY    PROC      NEAR
  124.            MOV       DL,AL          ;byte to display
  125.            MOV       AH,2           ;display byte function
  126.            INT       21H            ;execute
  127.            RET
  128.            ENDP                     ;DISPLAY
  129.  
  130. ;-------------------------------------;
  131. ;             STR_DISPLAY             ;
  132. ; Display the string at DX terminated ;
  133. ; by a dollar sign to the screen      ;
  134. ;-------------------------------------;
  135.  
  136. STR_DISPLAY PROC     NEAR
  137.            MOV       AH,9           ;string output function
  138.            INT       21H            ;execute
  139.            RET
  140.            ENDP                     ;STR_DISPLAY
  141.  
  142. ;-------------------------------------;
  143. ;            Program Data             ;
  144. ;-------------------------------------;
  145.  
  146. CTL_START  LABEL     WORD
  147.            DB        27,'['         ;start of reassignment sequence
  148. CTL_END    LABEL     WORD
  149.            DB        'p$'           ;end of reassignment sequence
  150.  
  151. KEYMESS    DB        10,'Key Reassignment',13,10,'$'
  152. KEYMESS2   DB           '--> $'
  153.  
  154. KEYEMESS   DB  10,'Error in parameters: <key code> <output>',13,10
  155.            DB     '  Each parameter may consist of any combination of',13,10
  156.            DB     '  strings in double quotes and decimal ASCII codes,',13,10
  157.            DB     '  seperated by semicolons.',13,10,'$'
  158.            ENDP
  159. 
  160.